﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class AddRequestParamter : System.Web.UI.Page
    {
        private int apiId; 
        protected void Page_Load(object sender, EventArgs e)
        {
            apiId = Convert.ToInt32(Request.QueryString["ID"]); 
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = "INSERT INTO RequestParameter(APIID,Name,Required,Range,Description,[Default]) VALUES(@APIID,@Name,@Required,@Range,@Description,@Default);";
 
            SqlParameter[] parameters = new SqlParameter[6];
            parameters[0] = new SqlParameter("@APIID", apiId);
            parameters[1] = new SqlParameter("@Name",TxtName.Text.Trim());
            parameters[2] = new SqlParameter("@Required", CbRequried.Checked);
            parameters[3] = new SqlParameter("@Range",TxtRange.Text.Trim());
            parameters[4] = new SqlParameter("@Description",TxtDescription.Text);
            parameters[5] = new SqlParameter("@Default",TxtDefault.Text.Trim());

            if(SqlHelper.ExecuteNonQuery(SqlHelper.OnlineAPIConnectionString, CommandType.Text, sql, parameters)>0)
                Response.Redirect("~/APIDetail.aspx?ID=" + apiId);
            else
                Response.Write("ERROR!");
        }
    }
}